//
//  huodongTableViewCell.m
//  maocuhuiOASystem
//
//  Created by michael on 17/1/9.
//  Copyright © 2017年 czd. All rights reserved.
//
#import "UIView+ViewController.m"
#import "huodongTableViewCell.h"
#import "chuguoViewController.h"

@implementation huodongTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
          self.selectionStyle = UITableViewCellSelectionStyleNone;
    
       _label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, 40)];
         _label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, _label.bottom, 100, 40)];
//     UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, 40)];
    _label.text = @"预报人员姓名 :";
    _label.numberOfLines = 0;
    _label.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:_label];
//     UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, label.bottom, 100, 40)];
    _label2.text = @"在外职位 :";
    _label2.numberOfLines = 0;
    _label2.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:_label2];

    _xingmingField = [[UITextView alloc]init];
//    _xingmingField.tag = indexPath.row-7;
      _xingmingField.frame = CGRectMake(_label.right, _label.top+10, KScreenWidth-120, 35);

      UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
      _xingmingField.backgroundColor = myColor;
      [_xingmingField setFont:[UIFont systemFontOfSize:12]];
      _xingmingField.delegate = self;
       [self.contentView addSubview:_xingmingField];
       
       _zhiweiField = [[UITextView alloc]init];
//       _zhiweiField.tag = indexPath.row-7;
      _zhiweiField.frame = CGRectMake(_label.right, _label.bottom+10, KScreenWidth-120, 35);

      _zhiweiField.backgroundColor = myColor;
      [_zhiweiField setFont:[UIFont systemFontOfSize:12]];
      _zhiweiField.delegate = self;
       [self.contentView addSubview:_zhiweiField];

    
    
    

}

return self;

}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
//if (textView == _beifenField||textView == _TextField1||textView == _dayField) {
//    [UIView animateWithDuration:0.2 animations:^{
//    self.view.transform = CGAffineTransformMakeTranslation(0, -100);
//    }];
//
//}
chuguoViewController *vc = (chuguoViewController *)self.ViewController;

UIView *view = textView.superview;

while (![view isKindOfClass:[UITableViewCell class]]) {

view = [view superview];

}

UITableViewCell *cell = (UITableViewCell*)view;

CGRect rect = [cell convertRect:cell.frame toView:self.ViewController.view];

if (rect.origin.y / 2 + rect.size.height>=KScreenHeight-216-46-64-47) {

vc.tableView.contentInset = UIEdgeInsetsMake(0, 0, 216, 0);

[vc.tableView scrollToRowAtIndexPath:[vc.tableView indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];

}





  
    return YES;
}

- (void)setModel:(PayTypeModel *)model
{
    _model = model;
//    self.model.Name = _xingmingField.text;
//    self.model.zhiwu = _zhiweiField.text;
    
    _xingmingField.text = self.model.Name;
    _zhiweiField.text =  self.model.zhiwu;

    

}

- (void)textViewDidChange:(UITextView *)textView
{
  self.model.Name = _xingmingField.text;
  self.model.zhiwu = _zhiweiField.text;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
